package com.cskaoyan.controller.admin;

import com.cskaoyan.bean.BasePageData;
import com.cskaoyan.bean.BaseParam;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.User;
import com.cskaoyan.service.UserService;
import com.cskaoyan.utils.EncryptUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author tangjian
 * @Date 2021/10/18 20:53
 * @description
 */

@RestController
@RequestMapping("admin")
public class UserController {

    @Autowired
    UserService userService;

    @RequiresPermissions("admin:user:list")
    @RequestMapping("/user/list")
    public BaseRespVo userList(String username, String mobile, BaseParam param){

        BasePageData data = userService.query(username,mobile,param);

        return BaseRespVo.ok(data);
    }

    @RequiresPermissions("admin:user:list")
    @PostMapping("/user/update")
    public BaseRespVo userUpdate(@RequestBody User user){

        //加密
        user.setPassword(EncryptUtil.MD5(user.getPassword()));
        userService.update(user);
        return BaseRespVo.ok();
    }

    @RequiresPermissions("admin:user:list")
    @RequestMapping("/user/detail")
    public BaseRespVo userDetail(Integer id){

        return userService.query(id);
    }

    @RequiresPermissions("admin:address:list")
    @RequestMapping("/address/list")
    public BaseRespVo addressList(String name,Integer userId,BaseParam param){

        BasePageData basePageData = userService.addressQuery(name, userId, param);
        return BaseRespVo.ok(basePageData);
    }

    @RequiresPermissions("admin:collect:list")
    @RequestMapping("/collect/list")
    public BaseRespVo collectList(Integer valueId,Integer userId,BaseParam param){

        BasePageData basePageData = userService.collectQuery(valueId, userId, param);
        return BaseRespVo.ok(basePageData);
    }

    @RequiresPermissions("admin:footprint:list")
    @RequestMapping("/footprint/list")
    public BaseRespVo footprintList(Integer userId,Integer goodsId,BaseParam param){

        BasePageData basePageData = userService.footprintQuery(userId, goodsId, param);
        return BaseRespVo.ok(basePageData);
    }

    @RequiresPermissions("admin:history:list")
    @RequestMapping("/history/list")
    public BaseRespVo historyList(Integer userId,String keyword,BaseParam param){
        BasePageData basePageData = userService.historyQuery(userId, keyword, param);
        return BaseRespVo.ok(basePageData);
    }

    @RequiresPermissions("admin:feedback:list")
    @RequestMapping("/feedback/list")
    public BaseRespVo feedbackList(Integer id,String username,BaseParam param){
        BasePageData basePageData = userService.feedbackQuery(username, id, param);
        return BaseRespVo.ok(basePageData);
    }

}
